package chixing.day10.homework;

import java.util.Calendar;

public class Factory_demo {
    //3.简单工厂，根据传入的数据判断具体类型
    public static Product createProduct(String type){
        if (type.equals("A"))
            return new ProductA();
        return new ProductB();
    }

    //4.客户端的调用
    public static void main(String[] args) {
        Product product1 = Factory_demo.createProduct("A");
        product1.show();
        Product product2 = Factory_demo.createProduct("B");
        product2.show();
    }
}
//1.抽象的产品
interface Product {
    void show();
}
//2.具体的产品A
class ProductA implements Product{
    @Override
    public void show() {
        System.out.println("产品A");
    }
}
//2.具体的产品B
class ProductB implements Product{
    @Override
    public void show() {
        System.out.println("产品B");
    }
}

